class AssignmentList(list):
    """This class simply keeps a sequence of assignments, as well as a dictionary mapping each 
    activity to its respective assignment. It should be treated as a list using append() and pop(). 
    The assignment list can be indexed with an integer (like a list) or using an Activity object as 
    a key (uses the {Activity: Assignment} mapping)."""
    def __init__(self, assignments=()):
        list.__init__(self)
        self.mapping = dict()
        self.extend(assignments)
        
    def __getitem__(self, key):
        if isinstance(key, int):
            return list.__getitem__(self, key)
        else:
            return self.mapping[key]
            
    def __setitem__(self, key, value):
        raise NotImplementedError()
        
    def __delitem__(self, key):
        if isinstance(key, int):
            self.pop(key)
        else:
            self.remove(self.mapping[key])
            
    def append(self, assignment):
        activity = assignment.activity
        if activity in self.mapping:
            raise ValueError("activity is already in the assignment list")
        list.append(self, assignment)
        self.mapping[activity] = assignment
        
    def extend(self, assignments):
        for assignment in assignments:
            self.append(assignment)
            
    def pop(self, index=-1):
        assignment = list.__getitem__(self, index)
        activity = assignment.activity
        if self.mapping[activity] is not assignment:
            raise ValueError("unexpected assignment object")
        list.__delitem__(self, index)
        del self.mapping[activity]
        return assignment
        
    def remove(self, assignment):
        activity = assignment.activity
        if self.mapping[activity] is not assignment:
            raise ValueError("unexpected assignment object")
        list.remove(self, assignment)
        del self.mapping[activity]
        
